home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 17 / Computer Interactive cdrom 17 - gen 99.iso / ZDNETIT / CONTENT / SMTPCEMS.ZIP / READS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-15  |  2.8 KB  |  97 lines

  1. /*
  2. **  READS.C [edit EMAIL.H before compiling]
  3. **
  4. **  This program reads all email message
  5. **  and saves them to disk.
  6. */
  7.  
  8. #include <windows.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "see.h"
  12. #include "email.h"
  13.  
  14. #define QUOTE 0x22
  15.  
  16. static char Buffer[1024];
  17.  
  18. void ErrorExit(int Code)
  19. {seeErrorText(Code,(LPSTR)Buffer,512);
  20.  printf("SEE Error %d: %s\n", Code, Buffer);
  21.  seeClose();
  22.  exit(1);
  23. }
  24.  
  25. void main(void)
  26. {int i, Code;
  27.  int Version; 
  28.  int Count;
  29.  int MsgNbr;
  30.  long MsgSize;
  31.  long BytesRead;
  32.  static char Filename[65];
  33.  
  34.  /* display parameters */
  35.  
  36.  Version = seeStatistics(SEE_GET_VERSION);
  37.  printf("SEE4C Version %1x.%1x.%1x\n",0x0f&(Version>>8),0x0f&(Version>>4),0x0f&Version);
  38.  printf("Server : %s\n",(LPSTR)POP3_HOST_NAME);
  39.  printf("  User : %s\n",(LPSTR)POP3_USER_NAME);
  40.  printf("  Pass : %s\n",(LPSTR)POP3_PASSWORD);
  41.  
  42.  /* define diagnostics log file */
  43.  ///seeStringParam(SEE_LOG_FILE, (LPSTR)"reader.log"); 
  44.  /* connect to POP3 server */
  45.  puts("Connecting...");
  46.  Code = seePop3Connect(
  47.     (LPSTR)POP3_HOST_NAME,             /* POP3 server */
  48.     (LPSTR)POP3_USER_NAME,             /* user */ 
  49.     (LPSTR)POP3_PASSWORD);             /* Password */
  50.  if(Code<0) ErrorExit(Code); 
  51.  /* get # messages waiting  */
  52.  puts("Getting message count...");
  53.  Count = seeGetEmailCount();                   
  54.  if(Count<0) ErrorExit(Count); 
  55.  printf("%d messages waiting.\n", Count);
  56.  /* any email waiting ? */
  57.  if(Count==0)
  58.    {printf("No messages waiting\n");
  59.     seeClose();
  60.     exit(1);
  61.    } 
  62.  /* read email messages */   
  63.  for(MsgNbr=1;MsgNbr<=Count;MsgNbr++)
  64.    {/* read message  */
  65.     MsgSize = seeGetEmailSize(MsgNbr);
  66.     if(MsgSize<0) ErrorExit((int)MsgSize);
  67.     /////printf("Message %d has %ld bytes\n", MsgNbr, MsgSize);    
  68.     /* turn off AUTO CALL driver */
  69.     seeIntegerParam(SEE_AUTO_CALL_DRIVER, 0); 
  70.     /////printf("Reading message %d...\n",MsgNbr);
  71.     /* construct filename */
  72.     wsprintf((LPSTR)Filename,(LPSTR)"email%1d.mai",MsgNbr);
  73.     printf("Saving message %d to '%s'\n", MsgNbr, Filename);
  74.     /////Code = seeGetEmailFile(MsgNbr, Filename, "c:\\temp", "c:\\temp");
  75.     Code = seeGetEmailFile(MsgNbr, Filename, ".", ".");
  76.     if(Code<0) ErrorExit(Code);
  77.     /* run the driver */
  78.     for(i=0;;i++)
  79.       {Code = seeDriver();
  80.        if(Code<0) ErrorExit(Code);
  81.        if(((i%10)==9)||(Code==0))
  82.          {/* display progress on last call & every 10th call to seeDriver() */
  83.           BytesRead = (long) seeStatistics(SEE_GET_TOTAL_BYTES_READ);
  84.           printf("%ld bytes read.\r",BytesRead);
  85.          }
  86.        if(Code==0) break;
  87.        }
  88.     printf("\n");    
  89.     /* turn AUTO CALL back on for seeClose */
  90.     seeIntegerParam(SEE_AUTO_CALL_DRIVER, 1);
  91.     if(Code<0) ErrorExit(Code); 
  92.    }
  93.  seeClose();
  94. } /* end main */
  95.  
  96.  
  97.